﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace ImTag.Silverlight
{
    public partial class ImageDisplayPanel : UserControl
    {
        public ImageDisplayPanel()
        {
            InitializeComponent();
            this.NewTagButton.Click += (source, ev) =>
                {
                    if (this.NewTagTextBox.Text != "" && this.Thumbnail != null)
                    {
                        var service = new ImTagService.ImTagServiceSoapClient();
                        service.AddTagCompleted += (source2, ev2) =>
                            {
                                this.Thumbnail.AddTag(this.NewTagTextBox.Text);
                                this.Thumbnail = this.Thumbnail;
                            };
                        service.AddTagAsync(this.NewTagTextBox.Text, this.Thumbnail.ImagePath);
                    }
                };
            this.Visibility = System.Windows.Visibility.Collapsed;
        }
        private Thumbnail activeThumb;
        public Thumbnail Thumbnail
        {
            get { return activeThumb; }
            set
            {
                this.Visibility = System.Windows.Visibility.Visible;
                this.activeThumb = value;

                this.Image.Source = activeThumb.Image.Source;

                this.WrapPanel.Children.Clear();
                foreach (var tag in value.Tags)
                    this.WrapPanel.Children.Add(new Tag() { TagText = tag });
            }
        }
    }
}
